package com.hkyp.ss.course.web;

import com.hkyp.ss.course.web.config.SystemInterceptor;
import com.hkyp.ss.course.web.config.annatation.EnableGlobalExceptionHandler;
import com.hkyp.ss.course.web.config.annatation.EnableSwagger;
import com.hkyp.ss.course.web.config.annatation.EnableSystemInterceptor;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
@EnableSwagger
@EnableGlobalExceptionHandler
@EnableSystemInterceptor
public class CourseWebApplication implements WebMvcConfigurer {

	public static void main(String[] args) {
		SpringApplication.run(CourseWebApplication.class, args);
	}

	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		registry.addInterceptor(getMyInterceptor())
				.excludePathPatterns("/swagger-resources/**", "/webjars/**", "/v2/**", "/swagger-ui.html/**")
				.excludePathPatterns("/login/admin/**").excludePathPatterns("/finance/**");
	}

	@Bean
	public SystemInterceptor getMyInterceptor(){
		return new SystemInterceptor();
	}

}
